<?php namespace Home\Controller;
//use Hdphp\Controller\Controller;
/**
 * 订单控制器
 */
class OrderController extends CommonController
{
	public function index()
	{
		if(IS_AJAX){
			unset($_SESSION['order']);
			$a = $_POST['a'];
			$a = rtrim($a,',');
			$a = explode(',', $a);
			foreach($a as $k=>$v){
				$_SESSION['order'][$v] = $_SESSION['cart']['goods'][$v];
			}
			foreach($_SESSION['order'] as $k=>$v){
				if(!is_array($_SESSION['order'][$k]['options'])){
			       $_SESSION['order'][$k]['options'] = explode(',', $v['options']);
				}
		    }		
			echo json_encode($phpdata=1);
			die;
		}
		if(isset($_SESSION['order']))
		{
		$orderData = $_SESSION['order'];				
//		p($orderData);
		$tot = 0;
		foreach($orderData as $k=>$v){
			$tot = $tot+$v['total'];
		}
		//实例化地址表
		$adData = Db::table('address')->where('uid',$_SESSION['id'])->get();
		View::with('adData',$adData);
		View::with('tot',$tot);
		View::with('orderData',$orderData);
		}		
		View::make();
	}
}
